<?php
/**
 * Created by PhpStorm.
 * User: lhuan
 * Date: 2019/11/7
 * Time: 0:01
 */
namespace app\index\model;

use think\Model;

class Blogroll extends Model
{
    public $map = [];
    public $fields = '*';

    public static function getBlogroll($isAll = false,$s = false){
        $where = [
            'status'=>1,
            'is_home' => ['neq',1]
        ];
        if(!empty($s)){
            foreach($s as $k => $e){
                if(!empty($e)){
                    $where[$k] = ['like','%'.$e.'%'];
                }
            }
        }
        if($_SERVER['REQUEST_URI'] == '/' || $isAll){
            unset($where['is_home']);
        }
        return Blogroll::where($where)->order('sort desc,update_time desc')->select();
    }
    public static function modify($data)
    {
        $date = date('Y-m-d H:m:s');
        $data['update_time'] = $date;
        return Blogroll::update($data);
    }

    public static function remove($id)
    {
        return Blogroll::where(['id'=>$id])->setField('status',0);
    }

    public static function add($data)
    {
        $date = date('Y-m-d H:m:s');
        $data['create_time'] = $data['update_time'] = $date;
        return Blogroll::insertGetId($data);
    }

}